/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.administracion;

import com.debug.Debug;
import com.util.Conectar;
import com.util.Utils;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import javax.naming.NamingException;

/**
 *
 * @author victor
 */
public class ListaUsuarios {

    public ArrayList getLista(){
        ArrayList lista=null;
        Connection conexion=null;
        ResultSet rs=null;
        try {
            conexion = Conectar.getConnection();
            String selectCustomerStr;

            selectCustomerStr = "SELECT nick, nombre, cuota FROM usuarios";

            PreparedStatement selectStatement = null;
            selectStatement =  conexion.prepareStatement(selectCustomerStr);

            Debug.getInstance().putLog(null, "Consulta: "+selectStatement.toString());

            rs = selectStatement.executeQuery();
            UsuarioBean usuario;
            lista=new ArrayList();
            String aux;
            while (rs.next()){
                usuario=new UsuarioBean();
                usuario.setNick(rs.getString(1));
                usuario.setNombre(rs.getString(2));
                usuario.setCuota(rs.getString(3));
                lista.add(usuario);
            }
            rs.close();
            conexion.close();
        } catch (NamingException ex) {
            ex.printStackTrace();
        } catch (SQLException ex) {
            ex.printStackTrace();
        } finally{
            try {
                if(rs!=null)rs.close();
                if(conexion!=null)conexion.close();
            } catch (SQLException ex) {
                ex.printStackTrace();
            }
        }
        return lista;
    }
   
}
